package cn.sdhuijin.healthexam.control;

import java.util.Properties;

import android.app.Activity;
import android.widget.EditText;

public class EditTextViewControl implements IControl {
	private Activity activity;
	private EditText editText;
	private String name;

	public EditTextViewControl(Activity activity, int editTextId, String name) {
		this.activity = activity;
		this.editText = (EditText) this.activity.findViewById(editTextId);
		if (this.editText == null) {
			throw new RuntimeException(name + " EditText dont exist!");
		}
		this.name = name;
	}

	@Override
	public void getValue(Properties prop) {
		String value = this.editText.getText().toString().trim();
		if (value != null) {
			prop.setProperty(this.name, value);
		} else {
			prop.setProperty(this.name, "");
		}

	}

	@Override
	public void setValue(Properties prop) {
		String value = prop.getProperty(this.name);
		if (value != null) {
			this.editText.setText(value);
		}
	}
}
